package cn.org.mrliu.ssm.test.module.${modelNameUncapFirst};

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.org.mrliu.ssm.common.test.BaseSpringTestSupport;
import cn.org.mrliu.ssm.model.${modelName};
import cn.org.mrliu.ssm.mapper.${modelName}Mapper;

public class Test${modelName}Mapper extends BaseSpringTestSupport{
	private static final Logger log = LoggerFactory.getLogger(Test${modelName}Mapper.class);
	@Resource
	private ${modelName}Mapper ${modelNameUncapFirst}Mapper;
	
	@Test
	public void getIds() throws Exception {
		List<Integer> ids = ${modelNameUncapFirst}Mapper.getIds(null);
		log.debug("ids:"+ids);
	}
	
	@Test
	public void getIdsByCondition() throws Exception {
		Map<String, Object> map = new HashMap<>();
		map.put("name", "%name%");
		List<Integer> ids = ${modelNameUncapFirst}Mapper.getIds(map);
		log.debug("ids:"+ids);
	}
	
	@SuppressWarnings("unchecked")
	@Test
	public void getList() throws Exception {
		List<${modelName}> list = (List<${modelName}>) ${modelNameUncapFirst}Mapper.getList(null);
		for (${modelName} ${modelNameUncapFirst} : list) {
			log.debug(${modelNameUncapFirst}.toString());
		}
	}
	
	@SuppressWarnings("unchecked")
	@Test
	public void getListByCondition() throws Exception {
		Map<String, Object> map = new HashMap<>();
		map.put("name", "test");
		List<${modelName}> list = (List<${modelName}>) ${modelNameUncapFirst}Mapper.getList(map);
		for (${modelName} ${modelNameUncapFirst} : list) {
			log.debug(${modelNameUncapFirst}.toString());
		}
	}
	
	@Test
	public void getCount() throws Exception {
		Integer count = ${modelNameUncapFirst}Mapper.getCount(null);
		log.debug("count:"+count);
	}
	
	@Test
	public void getCountByCondition() throws Exception {
		Map<String, Object> map = new HashMap<>();
		map.put("name", "%name%");
		Integer count = ${modelNameUncapFirst}Mapper.getCount(map);
		log.debug("count:"+count);
	}
	
	@Test
	public void getPageList() throws Exception {
		Map<String, Object> param = new HashMap<>();
		param.put("keyword", "");
		param.put("name", "test");
		@SuppressWarnings("unchecked")
		List<Map<String, Object>> list = (List<Map<String, Object>>) ${modelNameUncapFirst}Mapper.getPageList(param);
		log.debug("pageList:"+list);
	}
	
	
	@Test
	public void save() throws Exception {
		${modelName} ${modelNameUncapFirst} = new ${modelName}();
		${modelNameUncapFirst}.set${firstColumnNameCapFirst}("test save...");
		Integer id = ${modelNameUncapFirst}Mapper.save(${modelNameUncapFirst});
		System.out.println(id);
	}
	
	@Test
	public void update() throws Exception {
		${modelName} ${modelNameUncapFirst} = new ${modelName}();
		${modelNameUncapFirst}.setId(1);
		${modelNameUncapFirst}.set${firstColumnNameCapFirst}("test update....");
		${modelNameUncapFirst}Mapper.update(${modelNameUncapFirst});
	}
	
	@Test
	public void delete() throws Exception {
		${modelNameUncapFirst}Mapper.delete(1);
	}
	
	@Test
	public void batchSave() throws Exception {
		List<${modelName}> ${modelNameUncapFirst}s = new ArrayList<>();
		${modelName} ${modelNameUncapFirst} = null;
		${modelNameUncapFirst} = new ${modelName}();
		${modelNameUncapFirst}.set${firstColumnNameCapFirst}("batchSave test 1");
		${modelNameUncapFirst}s.add(${modelNameUncapFirst});
		${modelNameUncapFirst} = new ${modelName}();
		${modelNameUncapFirst}.set${firstColumnNameCapFirst}("batchSave test 2");
		${modelNameUncapFirst}s.add(${modelNameUncapFirst});
		${modelNameUncapFirst} = new ${modelName}();
		${modelNameUncapFirst}.set${firstColumnNameCapFirst}("batchSave test 3");
		${modelNameUncapFirst}s.add(${modelNameUncapFirst});
		${modelNameUncapFirst}Mapper.batchSave(${modelNameUncapFirst}s);
	}
	
	@Test
	public void batchUpdate() throws Exception {
		${modelName} ${modelNameUncapFirst} = new ${modelName}();
		${modelNameUncapFirst}.set${firstColumnNameCapFirst}("batchUpdate test...");
		Map<String, Object> param = new HashMap<>();
		param.put("ids", new Integer[]{1,2,3,4,5});
		param.put("object", ${modelNameUncapFirst});
		${modelNameUncapFirst}Mapper.batchUpdate(param);
	}
	
	@Test
	public void batchDelete() throws Exception {
		Map<String, Object> param = new HashMap<>();
		param.put("ids", new Integer[]{1,2,3});
		${modelNameUncapFirst}Mapper.batchDelete(param);
	}
}